package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.nbMeter.NbMeterDeleteModel;
import com.hzhr.iot.device.model.nbMeter.NbMeterGetModel;
import com.hzhr.iot.device.model.nbMeter.NbMeterPostModel;
import com.hzhr.iot.device.model.nbMeter.NbMeterPutModel;
import com.hzhr.iot.device.model.nbMeter_sell.NbMeter_SellGetModel;
import com.hzhr.iot.device.model.nbMeter_sell.NbMeter_SellPostModel;
import com.hzhr.iot.device.service.NbMeterService;
import com.hzhr.iot.device.service.NbMeter_SellService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "NbMeter_Sell", description = "NB物联表的销售")
@RestController
@RequestMapping(value = "")
public class NbMeter_SellController extends BaseController {
    @Autowired
    NbMeter_SellService nbMeter_SellService;

    //region /nb-meters/{nbMeterId}/sell POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 获取NB表  \n----异常说明 : NB表不存在  \n\n----异常代码 : 202  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证购买公司的合法性  \n----异常说明 : 购买公司不合法  \n\n----异常代码 : 203  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证NB表是否具备销售条件  \n----异常说明 : NB表已经销售，无法继续销售  \n\n----异常代码 : 204  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证NB表是否具备销售条件  \n----异常说明 : NB表没有代码，无法销售  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="销售NB表", notes="销售NB表  \n1. 获取NB表：查询登录用户所在公司下的NB表物联台账  \n2, 验证NB表是否具备销售条件：如果该NB表的物联网台账有所属的燃气公司，或则没有代码，则不具备销售条件  \n3. 验证购买公司的合法性：查询购买公司，如果购买公司不存在或者不是燃气公司，则不合法  \n4. 将NB物联表分配到购买公司的顶级部门下：修改NB表的物联台账，将其分配到购买公司的顶级部门下  \n5. 返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/nb-meters/{nbMeterId}/sell", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<NbMeter_SellGetModel> post(@PathVariable("nbMeterId") Integer nbMeterId,
                                                     @RequestParam @ApiIgnore Map<String, Object> query,
                                                     @RequestBody NbMeter_SellPostModel body) throws ServiceException {
        NbMeter_SellGetModel responseBody = nbMeter_SellService.post(initHeader(), nbMeterId, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion

}

















































































































































































































































































































































































































































































































































































































































































